import qs from 'qs'
import { axios as request } from '@/utils/request'

// 权限-部门树
export function queryTreeByKeyWord(params) {
  return request({
    url: '/sys/sysDepart/queryTreeByKeyWord',
    method: 'get',
    params
  })
}

//同步钉钉
export function dingtalkSaveUsers(params) {
  return request({
    url: '/dingtalk/saveUsers',
    method: 'get',
    params,
    timeout: 12000000000
  })
}


//设置 取消成本部门
export function editDepartType(data) {
  return request({
    url: '/sys/sysDepart/editDepartType',
    method: 'put',
    data
  })
}


//根据部门id查人员
export function queryPageListByDepartId(params) {
  return request({
    url: '/sys/user/queryPageListByDepartId',
    method: 'get',
    params
  })
}

//获取角色列表
export function roleGetRoles(params) {
  return request({
    url: '/sys/role/getRoles',
    method: 'get',
    params
  })
}

//保存用户角色
export function userEditUserRole(data) {
  return request({
    url: '/sys/user/editUserRole',
    method: 'post',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    data: qs.stringify(data, { arrayFormat: 'repeat' })
  })
}

//新增重复性检查
export function roleCheckRoleCode(params) {
  return request({
    url: '/sys/role/checkRoleCode',
    method: 'get',
    params
  })
}


//新增角色
export function roleAdd(data) {
  return request({
    url: '/sys/role/add',
    method: 'post',
    data
  })
}
//同步组织架构
export function refreshSyncOrganizationQuart(data) {
  return request({
    url: '/sync/sysUserIwork/syncOrganizationQuart',
    method: 'post',
    data,
    timeout: 120000
  })
}


//删除角色
export function roleDelete(data) {
  return request({
    url: '/sys/role/delete',
    method: 'delete',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    data: qs.stringify(data, { arrayFormat: 'repeat' })
  })
}

//编辑角色
export function roleEdit(data) {
  return request({
    url: '/sys/role/edit',
    method: 'put',
    data
  })
}


//权限树
export function roleQueryTreeList(params) {
  return request({
    url: '/sys/role/queryNewRolePermissionTreeList',
    method: 'get',
    params
  })
}
// 
//保存权限
export function saveRolePermissions(data) {
  return request({
    url: '/sys/role/saveRolePermissions',
    method: 'post',
    data
  })
}
//批量授权
export function batchAuthRole(data) {
  return request({
    url: '/sys/user/batchAuthRole',
    method: 'post',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    data: qs.stringify(data, { arrayFormat: 'repeat' })
  })
}

//数据权限
export function roleDatarule(params) {
  return request({
    url: `/sys/role/datarule/${params.id1}/${params.id2}`,
    method: 'get',
  })
}